﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace ZhimeiSoft.Framework.Client.Control.DateTimeGrid
{
    public partial class MonthDateTimeForWeek : UserControl, IDateTimeView
    {



        private MonthDateTimeForDay[] arrPanDateOne = null;
        private MonthDateTimeForDay[] arrPanDateTwo = null;
        private MonthDateTimeForDay[] arrPanDateThree = null;
        private MonthDateTimeForDay[] arrPanDateFour = null;
        private MonthDateTimeForDay[] arrPandateFive = null;
        private MonthDateTimeForDay[] arrPandateSix = null;


        public MonthDateTimeForWeek()
        {
            InitializeComponent();
            arrPanDateOne = new MonthDateTimeForDay[] { dateTimeForDay17, dateTimeForDay11, dateTimeForDay12, dateTimeForDay13, dateTimeForDay14, dateTimeForDay15, dateTimeForDay16 };
            arrPanDateTwo = new MonthDateTimeForDay[] { dateTimeForDay27, dateTimeForDay21, dateTimeForDay22, dateTimeForDay23, dateTimeForDay24, dateTimeForDay25, dateTimeForDay26 };
            arrPanDateThree = new MonthDateTimeForDay[] { dateTimeForDay37, dateTimeForDay31, dateTimeForDay32, dateTimeForDay33, dateTimeForDay34, dateTimeForDay35, dateTimeForDay36 };
            arrPanDateFour = new MonthDateTimeForDay[] { dateTimeForDay47, dateTimeForDay41, dateTimeForDay42, dateTimeForDay43, dateTimeForDay44, dateTimeForDay45, dateTimeForDay46 };
            arrPandateFive = new MonthDateTimeForDay[] { dateTimeForDay57, dateTimeForDay51, dateTimeForDay52, dateTimeForDay53, dateTimeForDay54, dateTimeForDay55, dateTimeForDay56 };
            arrPandateSix = new MonthDateTimeForDay[] { dateTimeForDay67, dateTimeForDay61, dateTimeForDay62, dateTimeForDay63, dateTimeForDay64, dateTimeForDay65, dateTimeForDay66 };
        }

        #region IDateTimeView 成员

        public DateTime getDateTime()
        {
            throw new NotImplementedException();
        }

        public void setDateTime(DateTime dateTime)
        {
            intWeekDate();

            int iMaxDays = DateTime.DaysInMonth(dateTime.Year, dateTime.Month);

            Stack<MonthDateTimeForDay[]> stackWeek = new Stack<MonthDateTimeForDay[]>();
            stackWeek.Push(arrPandateSix);
            stackWeek.Push(arrPandateFive);
            stackWeek.Push(arrPanDateFour);
            stackWeek.Push(arrPanDateThree);
            stackWeek.Push(arrPanDateTwo);
            stackWeek.Push(arrPanDateOne);

            MonthDateTimeForDay[] currWeek = arrPanDateOne;
            DateTime dtNow = new DateTime(dateTime.Year, dateTime.Month, 1);
            if (dtNow.DayOfWeek != DayOfWeek.Sunday)
            {
                dtNow = dateTime.AddDays(1 - Convert.ToInt32(dateTime.DayOfWeek.ToString("d")));
                dtNow = dtNow.AddDays(-1);
            }
            while (stackWeek.Count != 0)
            {
                currWeek = stackWeek.Pop();
                for (int i = 0; i < currWeek.Length; i++)
                {
                    currWeek[i].setDateTime(dtNow);
                    currWeek[i].setEffectiveColor(dtNow.Month == dateTime.Month);
                    dtNow = dtNow.AddDays(1);
                }
            }

            /*for (int iDay = 1; iDay <= iMaxDays; iDay++)
            {
                dtNow = new DateTime(dateTime.Year, dateTime.Month, iDay);
                currWeek[(int)dtNow.DayOfWeek].setDateTime(dtNow);
                if ((dtNow.DayOfWeek == DayOfWeek.Saturday)&&(stackWeek.Count != 0))
                {
                    currWeek = stackWeek.Pop();
                }
            }*/
        }

        public void addItem(string valueList)
        {
            throw new NotImplementedException();
        }

        public int getItemID()
        {
            throw new NotImplementedException();
        }

        public void delItem(int indexID)
        {
            throw new NotImplementedException();
        }

        public void initDate(DateTime dtInit)
        {
            throw new NotImplementedException();
        }
        public void setEffectiveColor(bool bEffective)
        {
            throw new NotImplementedException();
        }
        #endregion

        private void intWeekDate()
        {
            initDateTimeForDay(arrPanDateOne);
            initDateTimeForDay(arrPanDateTwo);
            initDateTimeForDay(arrPanDateThree);
            initDateTimeForDay(arrPanDateFour);
            initDateTimeForDay(arrPandateFive);
            initDateTimeForDay(arrPandateSix);
        }
        private void initDateTimeForDay(MonthDateTimeForDay[] arrDay)
        {
            foreach(MonthDateTimeForDay day in arrDay)
            {
                day.initDate(DateTime.Now);
            }
        }

        

        private void panDateFour_Click(object sender, EventArgs e)
        {

        }

        private void dateTimeForDay47_Load(object sender, EventArgs e)
        {

        }

        private void monthDateTimeForDay6_Load(object sender, EventArgs e)
        {

        }

        private void MonthDateTimeForWeek_Load(object sender, EventArgs e)
        {

        }


    }
}
